package com.hzcx.app.simplechat.ui.mine.dialog;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import butterknife.BindView;

/**
 * 修改用户昵称弹窗
 */
public class EditUserNickNameDialog extends BaseDialog {
    @BindView(R.id.et_nick_name)
    EditText etNickName;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_commit)
    TextView tvCommit;

    private String nickName;
    private OnEditNickNameListener listener;

    public EditUserNickNameDialog(@NonNull Context context,String nickName,OnEditNickNameListener listener) {
        super(context);
        this.nickName=nickName;
        this.listener=listener;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_edit_user_nickname;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        etNickName.setHint(nickName);

        tvCancel.setOnClickListener(view -> dismiss());

        tvCommit.setOnClickListener(view -> {
            if(EmptyUtils.isEmpty(etNickName.getText().toString())){
                showError("请输入昵称");
                return;
            }
            if(listener!=null){
                listener.editNickName(etNickName.getText().toString());
            }
            dismiss();
        });
    }

    @Override
    public void initData() {

    }

    public interface OnEditNickNameListener{
        void editNickName(String name);
    }
}
